package com.itboy.mall.sms.bounds.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.itboy.common.annotation.RepeatSubmit;
import com.itboy.common.annotation.Log;
import com.itboy.common.core.controller.BaseController;
import com.itboy.common.core.domain.AjaxResult;
import com.itboy.common.enums.BusinessType;
import com.itboy.mall.sms.bounds.vo.MallSpuBoundsVo;
import com.itboy.mall.sms.bounds.bo.MallSpuBoundsQueryBo;
import com.itboy.mall.sms.bounds.bo.MallSpuBoundsAddBo;
import com.itboy.mall.sms.bounds.bo.MallSpuBoundsEditBo;
import com.itboy.mall.sms.bounds.service.IMallSpuBoundsService;
import com.itboy.common.utils.poi.ExcelUtil;
import com.itboy.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 商品spu积分设置Controller
 *
 * @author itboy
 * @date 2021-08-07
 */
@Validated
@Api(value = "商品spu积分设置控制器", tags = {"商品spu积分设置管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/bounds/mall")
public class MallSpuBoundsController extends BaseController {

    private final IMallSpuBoundsService iMallSpuBoundsService;

    /**
     * 查询商品spu积分设置列表
     */
    @ApiOperation("查询商品spu积分设置列表")
    @PreAuthorize("@ss.hasPermi('bounds:mall:list')")
    @GetMapping("/list")
    public TableDataInfo<MallSpuBoundsVo> list(@Validated MallSpuBoundsQueryBo bo) {
        return iMallSpuBoundsService.queryPageList(bo);
    }

    /**
     * 导出商品spu积分设置列表
     */
    @ApiOperation("导出商品spu积分设置列表")
    @PreAuthorize("@ss.hasPermi('bounds:mall:export')")
    @Log(title = "商品spu积分设置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<MallSpuBoundsVo> export(@Validated MallSpuBoundsQueryBo bo) {
        List<MallSpuBoundsVo> list = iMallSpuBoundsService.queryList(bo);
        ExcelUtil<MallSpuBoundsVo> util = new ExcelUtil<MallSpuBoundsVo>(MallSpuBoundsVo.class);
        return util.exportExcel(list, "商品spu积分设置");
    }

    /**
     * 获取商品spu积分设置详细信息
     */
    @ApiOperation("获取商品spu积分设置详细信息")
    @PreAuthorize("@ss.hasPermi('bounds:mall:query')")
    @GetMapping("/{id}")
    public AjaxResult<MallSpuBoundsVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iMallSpuBoundsService.queryById(id));
    }

    /**
     * 新增商品spu积分设置
     */
    @ApiOperation("新增商品spu积分设置")
    @PreAuthorize("@ss.hasPermi('bounds:mall:add')")
    @Log(title = "商品spu积分设置", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody MallSpuBoundsAddBo bo) {
        return toAjax(iMallSpuBoundsService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改商品spu积分设置
     */
    @ApiOperation("修改商品spu积分设置")
    @PreAuthorize("@ss.hasPermi('bounds:mall:edit')")
    @Log(title = "商品spu积分设置", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody MallSpuBoundsEditBo bo) {
        return toAjax(iMallSpuBoundsService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除商品spu积分设置
     */
    @ApiOperation("删除商品spu积分设置")
    @PreAuthorize("@ss.hasPermi('bounds:mall:remove')")
    @Log(title = "商品spu积分设置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iMallSpuBoundsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
